package com.leetcode.LC;

public class LC367 {
    public boolean isPerfectSquare(int num) {
        if (num == 0) {
            return false;
        }
        int a = 0, b = num, mid;
        while (a <= b) {
            mid = a + (b - a) / 2;
            if ((long) mid * mid == num) {
                return true;
            } else if ((long) mid * mid < num) {
                a = mid + 1;
            } else if ((long) mid * mid > num) {
                b = mid - 1;
            }
        }
        return false;
    }

    public static void main(String[] args) {
        System.out.println(new LC367().isPerfectSquare(2));
    }
}
